<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter()

const languageList = ref<string[]>([])
const config = ref<any>({
  language:""
})

const messages = ref<any>({})

onMounted(()=>{
  window.gamerfinger.getLanguage().then(data=>{
    messages.value = data
  })

  window.gamerfinger.getConfig().then(data=>{
    config.value= data
  })

  window.gamerfinger.listLanguage().then(data=>{
    languageList.value= data
  })
})

function goHome(){
  router.push({
    name:"home",
  })
}

function changeLanguage(){
  window.gamerfinger.changeLanguage(config.value.language).then(data=>{
    messages.value = data
  })
}

</script>

<template>
  <!-- 设置页面 -->
  <main>
    <div class="glass-container">
      <h1 class="title">Gamer Finger</h1>
      <div class="settings">
        <div class="setting-item">
          <span class="label">{{ messages.lang || '语言' }}</span>
          <select v-model="config.language" @change="changeLanguage" class="language-select">
            <option v-for="language in languageList" :key="language" :value="language">{{ language }}</option>
          </select>
        </div>
      </div>
      <div @click="goHome" class="back-button">
        <span>{{messages.back || '返回'}}</span>
      </div>
    </div>
  </main>
</template>

<style scoped>
main {
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.8), rgba(30, 30, 40, 0.9));
  box-sizing: border-box;
}

.glass-container {
  width: 100%;
  max-width: 500px;
  padding: 32px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.title {
  font-size: 2.5rem;
  font-weight: 700;
  color: #fff;
  text-align: center;
  margin: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #fff, #a9c4c2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.settings {
  width: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setting-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.setting-item:hover {
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.label {
  font-size: 1rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.language-select {
  width: 140px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.language-select:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(169, 196, 194, 0.5);
}

.language-select:focus {
  outline: none;
  border-color: rgba(169, 196, 194, 0.8);
  box-shadow: 0 0 0 2px rgba(169, 196, 194, 0.3);
}

.language-select option {
  background: rgba(30, 30, 40, 0.95);
  color: #fff;
}

.back-button {
  box-sizing: border-box;
  width: 160px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: all 0.3s ease;
  transform: scale(1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(169, 196, 194, 0.4);
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.back-button:active {
  transform: scale(0.98);
  transition: transform 0.1s ease;
}

.back-button span {
  font-size: 1rem;
  font-weight: 500;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 隐藏滚动条 */
.language-select::-webkit-scrollbar {
  display: none;
}

.language-select {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
</style>